package com.ruoyi.repay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.repay.domain.RepaymentLog;
import com.ruoyi.repay.domain.RepaymentPlan;
import com.ruoyi.repay.domain.RepaymentSchedule;
import com.ruoyi.repay.domain.vo.ResultVo;
import com.ruoyi.repay.domain.vo.SearchVo;
import com.ruoyi.repay.mapper.RepayMapper;
import com.ruoyi.repay.mapper.RepaymentPlanMapper;
import com.ruoyi.repay.service.RepayService;
import com.ruoyi.repay.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RepayServiceImpl implements RepayService {
    @Autowired
    private RepayMapper repayMapper;
    @Autowired
    private RepaymentPlanMapper repaymentPlanMapper;
    @Autowired
    private RedisTemplate redisTemplate;
//    @Override
//    public ResultVo addrepaymentschedule(RepaymentSchedule repaymentSchedule) {
//        IdWorker idWorker = new IdWorker();
//        String outTradeNo = Long.toString(idWorker.nextId());
//        repaymentSchedule.setCode(outTradeNo);
//        repayMapper.addrepaymentschedule(repaymentSchedule);
//        return new ResultVo(200, "添加成功", null);
//    }

//    @Override
//    public ResultVo repayList(String userInfoCode) {
//
////        QueryWrapper<RepaymentPlan> qw = new QueryWrapper<>();
////        if (searchVo.getUserInfoCode()!=null && searchVo.getUserInfoCode()!=""){
////            qw.eq("user_info_code",searchVo.getUserInfoCode());
////        }
//       List<RepaymentPlan> list =  repaymentPlanMapper.repayList(userInfoCode);
//        return new ResultVo(200, "查询成功", list);
//    }

    @Override
    public ResultVo add(Integer id) {
       RepaymentPlan repaymentPlan = repaymentPlanMapper.selectById(id);
        IdWorker idWorker = new IdWorker();
        String outTradeNo = Long.toString(idWorker.nextId());
        repaymentPlan.setOutTradeNo(outTradeNo);
        repaymentPlanMapper.updateById(repaymentPlan);
    return new ResultVo(200, "添加成功", repaymentPlan);
    }

    @Override
    public ResultVo repaylist2() {
       List<RepaymentPlan> repaymentPlans = repaymentPlanMapper.repayList2();
       return new ResultVo(200, "查询成功", repaymentPlans);
    }


}
